<template>
  <div class="image-slot">
    <div class="clock-wrap">
      <div id="time">
        <div class="hour">
          <span style="color: #49c6d0">{{ hours }} </span>
        </div>
        <span style="color: #fff">:</span>
        <div class="minutes">
          <span style="color: #6a14e0">{{ minutes }} </span>
        </div>
        <span style="color: #fff">:</span>
        <div class="seconds">
          <span style="color: #e3c01e">{{ seconds }}</span>
        </div>
      </div>
    </div>
    <div class="cup-wrap">
      <div class="cup-box">
        <div class="saucer"></div>
        <div class="cup-body">
          <div class="layer"></div>
        </div>
        <div class="steam">
          <div class="steam-1"></div>
          <div class="steam-2"></div>
          <div class="steam-3"></div>
          <div class="steam-4"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onBeforeMount } from "vue";
const hours = ref("00");
const minutes = ref("00");
const seconds = ref("00");

const time = ref("");
let prevTime = new Date();
let timer = 0;

const loop = function () {
  clearInterval(timer);
  let time = new Date();
  updateTime(time);
  setInterval(() => {
    time = new Date()
    if (time.getTime() - prevTime.getTime() > 1050) {// 如果时间差大于50毫秒
      loop();
    }
    updateTime(time);
    prevTime = time;
  }, 1000);
};
const updateTime = function (time) {
  hours.value = time.getHours().toString().padStart(2, "0");
  minutes.value = time.getMinutes().toString().padStart(2, "0");
  seconds.value = time.getSeconds().toString().padStart(2, "0");
};
onBeforeMount(function () {
  loop();
});
</script>
<style scoped lang="scss">
.image-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-image: radial-gradient(circle, #000 0, #1b1b1f 70%, transparent 100%);
  border-radius: 120px;
}
.cup-wrap {
  transform: scale(0.4);
  width: 320px;
  height: 320px;
}
.cup-box {
  width: 160px;
  height: 160px;
  margin: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  &::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 100%;
    left: 0;
    top: -10px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.2));
    z-index: 1;
    border-radius: 50%;
  }
  &::after {
    content: "";
    position: absolute;
    top: 10%;
    right: -66px;
    width: 70px;
    height: 110px;
    transform: rotate(4deg);
    background: transparent;
    border: 15px solid rgba(255, 255, 255, 0.6);
    border-left: none;
    border-radius: 30px 50% 90px 0;
  }

  .cup-body {
    display: flex;
    flex-direction: column-reverse;
    height: 100%;
    background: rgba(255, 255, 255, 0.4);
    clip-path: path("m 0 0 q 4.59 145.8 34.425 155.52 c 29.835 8.1 68.85 8.1 96.39 0 q 29.835 -9.72  29.835 -155.52 C 143 11 16 13 0 0 Z");
  }

  .layer {
    position: relative;
    height: 120px;
    background-color: #6f4e38;
    border-radius: 80px/10px;

    &::before {
      content: "";
      display: block;
      width: 100%;
      height: 20px;
      background: linear-gradient(to bottom, rgba(117, 78.56, 1), rgba(255, 255, 255, 0.3));
      border-radius: 50%;
    }
  }

  .steam {
    position: absolute;
    top: -40px;
    display: flex;
    width: 100%;
    justify-content: center;

    & > div {
      width: 2px;
      height: 40px;
      margin: 0 15px;
      background: #fff;
      animation: waft 3s linear infinite;
      filter: blur(5px);
    }
  }

  .saucer {
    width: 250px;
    height: 40px;
    background: #fff;
    position: absolute;
    border-radius: 20px 20px 50% 50%;
    bottom: 0;
    left: 50%;
    transform: translate(-50%, 25px);

    &::before {
      content: "";
      display: block;
      background: #ddd;
      width: 100%;
      height: 100%;
      top: 0px;
      clip-path: ellipse(50% 50% at 50% 0%);
      border: 5px solid #fff;
      border-radius: 20px;
    }

    &::after {
      content: "";
      display: block;
      background: #fff;
      width: 50%;
      height: 15px;
      border-radius: 0 0 40% 40%;
      margin: -3px auto;
      box-shadow: 0 15px 15px -5px #000;
    }
  }
}
.clock-wrap {
  transform: scale(0.6);
  width: 200px;
  padding-top: 15px;
  -webkit-box-reflect: below 1px linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}
#time {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: inherit;

  & > div {
    display: flex;
    height: 60px;
    width: 60px;
    justify-content: center;
    align-items: center;
    font-weight: 300;
    font-size: 2.5em;
    & > span {
      color: #fff;
    }
  }
}

@keyframes waft {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }

  100% {
    transform: translateY(-200px) scale(2);
    opacity: 0;
  }
}
@media (min-width: 640px) {
  .cup-wrap {
    transform: scale(0.6);
  }
  .clock-wrap {
    transform: scale(0.8);
  }
}
@media (min-width: 960px) {
  .cup-wrap {
    transform: scale(0.8);
  }
  .clock-wrap {
    transform: scale(1);
  }
}
</style>
